package com.awesome.ipcdemo.multiprocess;

import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;

import androidx.annotation.Nullable;

import com.awesome.sdk.util.ShowLogUtil;

/**
 * Author: zhangjingfang
 * Email:zhangjingfang@jeejio.com
 * Date: 2021/7/30 9:28
 * Description:类描述
 */
public class MyService extends Service {

    private boolean mSuccess;

    @Override
    public void onCreate() {
        super.onCreate();
        ShowLogUtil.info("onCreate");
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        ShowLogUtil.info("onStartCommand");
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(5000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                mSuccess = true;
            }
        }).start();
        return super.onStartCommand(intent, flags, startId);
    }

    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        ShowLogUtil.info("onBind");
        return new MyBinder();
    }

    @Override
    public boolean onUnbind(Intent intent) {
        ShowLogUtil.info("onUnbind");
        return super.onUnbind(intent);
    }

    @Override
    public void onDestroy() {
        ShowLogUtil.info("onDestroy");
        super.onDestroy();
    }

    class MyBinder extends Binder {
        public boolean addFriend() {
            return mSuccess;
        }
    }
}
 
 